import axios from 'axios'
import qs from 'qs'

// 添加标签
export function insertLabel (labelInfo) {
    return axios.post(`label`, labelInfo)
}

// 更新标签
export function updateLabel (updateInfo) {
    return axios.put(`label/${updateInfo.id}`, updateInfo)
}

// 删除标签
export function deleteLabel (labelId) {
    return axios.delete(`label/${labelId}`)
}

// 获取标签信息
export function listLabel (queryInfo) {
    return axios.get(`label`, { params: queryInfo })
}

// 分页获取标签信息
export function pageLabel (queryInfo) {
    return axios.get(`label/${queryInfo.page}/${queryInfo.size}`, {
        params: {
            ids: queryInfo.ids,
            names: queryInfo.names,
            statuses: queryInfo.statuses,
            asc: queryInfo.asc,
            desc: queryInfo.desc
        },
        paramsSerializer: params => {
            return qs.stringify(params, { indices: false })
        }
    })
}

// 获取当前用户关注的标签
export function currentAttentionLabels () {
    return axios.get(`label/attention`)
}

// 关注标签
export function attentionLabel (id) {
    return axios.post(`label/attention/${id}`)
}

// 取消关注标签
export function removeAttentionLabel (id) {
    return axios.delete(`label/attention/${id}`)
}

// 分页获取关注了标签的用户
export function pageAttentionLabelUsers (queryInfo) {
    return axios.get(`label/attention/${queryInfo.labelId}/${queryInfo.page}/${queryInfo.size}`)
}

// 获取用户关注的标签
export function attentionLables (userId) {
    return axios.get(`label/attention/user/${userId}`)
}
